/********************************************************
* @file: SurfSurfCrv.hpp (v3.81)
* @date: 15/12/2012
* @author: Ricardo C. Marques
**********************************************************/
/*

** CLASS DESCRIPTION
SurfSurfCrv creates a curve on surface by topologically 
intersecting exactly two given patch2d's, resulting in 
a polyline. This curve is created dangling, so it does 
not split the original meshes.

** CLIENT-AVAILABLE METHODS
Besides all constructors and destructor, all 
methods whose name starts with lowercase:

  SurfSurfCrv( mgPatch2d* _p2dFirst,
         mgPatch2d* _p2dSecond );
  ~SurfPlaneCrv();
  int SurfSurfCrv::getNumberOfCurves();
  int SurfSurfCrv::getCurveSize();  
  mgPoint3d* SurfSurfCrv::getFrstCurve();
  mgPoint3d* SurfSurfCrv::getNextCurve();

*/

#ifndef _SURFSURFCRV_HPP
#define _SURFSURFCRV_HPP

#include "ctopology/topology.hpp"

/* Auxiliary Header Files*/
#include "GenExactCurve.hpp"

/* Class SurfSurfCrv */
class triangIntersection;
class SurfSurfCrv : public GenExactCurve
{
  /* Constructor/Destructor */
public:
  SurfSurfCrv::SurfSurfCrv( cTopology* _p2dFirst,
    cTopology* _p2dSecond );
  virtual ~SurfSurfCrv();  

  /* Private Methods */

  /* Surface Methods */
private:
  void InitSurfCollector(size_t _SurfNumber);
  void InsertSurface( cTopology* _patch2d );
  void RemoveSurfaces();

  /* Intersection Methods */
private:
  void BuildCurves();
  bool CalculateIntersection( cTopology* _Mesh, int _TriIndex, double _S0[3], double _S1[3]);
  bool GetNextCandidate     ( int* MeshIndex1, int* ElemIndex1, int* MeshIndex2, int* ElemIndex2);
  void SearchIntersections  ( int _MeshIndex1, int _ElemIndex1, int _MeshIndex2, int _ElemIndex2);
  bool IsUnvisitedBoundPair(  int _Mesh1, int _Tri1, int _Mesh2, int _Tri2);
  bool IsUnvisitedInnerPair(  int _Mesh1, int _Tri1, int _Mesh2, int _Tri2);

  /* Private Variables */
private:

  /* Surface Arrays */
  size_t m_SurfaceIndex;
  size_t m_SurfacesNumber;
#if 0  // mtool3d 
  mgSurface** m_Surface;// Working Surface 
#endif
  cTopology** m_Mesh;    // Adjacent Walking Triangular 
  // Mesh of the Working Surface 

  /* Candidates Arrays*/
  triangIntersection* m_TriInt;
  size_t m_CurrentCandidate;
  size_t m_CandidatesArraySize;
  int* m_CandidatesArray; // Candidates, given by m_TriInt

};
#endif
